/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DATA.iDataSetParts;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Serializable;

/**
 * 
 * @author Bunkowski
 */
public class Measurement implements Serializable {

	public static final long serialVersionUID = 1L;// 7449758460627327651L;

	public String path, patientID, measurementID, sampleType, comment, filename;
	public String gcmsFilePath = "";

	public Measurement(String path) {

		this.path = path;
		this.measurementID = new File(path).getName().split("_")[1];
		this.filename = new File(path).getName();
		readInfos();

	}

	private void readInfos() {
		BufferedReader br = null;
		try {
			br = new BufferedReader(new FileReader(path));
			for (int i = 0; i < 13; i++) {
				br.readLine();
			}
			try {
				this.sampleType = br.readLine().split(",")[2]; // line 14 15 3rd comma separated block = sampletype
			} catch (Exception ex) {
				this.sampleType = "no sample type found";
			}
			try {
				this.patientID = br.readLine().split(",")[2]; // line 15 3rd comma separated block = ID
			} catch (Exception ex) {
				this.patientID = "no id found";
			}
			try {
				this.comment = br.readLine().split(",")[2];
			} catch (Exception ex) {
				this.comment = "no comment found";
			}

		} catch (FileNotFoundException e) {
			System.out.println("measurement fnf");
		} catch (IOException e) {
			System.out.println("measurement iox");
		}
	}

	public String ObjectToString() {
		String returnValue = "";

		returnValue = "ObjClass :" + this.getClass() + "\r\n";
		returnValue += "path :" + path + "\r\n";
		returnValue += "patientID :" + patientID + "\r\n";
		returnValue += "measurementID :" + measurementID + "\r\n";
		returnValue += "sampleType :" + sampleType + "\r\n";
		returnValue += "comment :" + comment + "\r\n";
		returnValue += "filename :" + filename + "\r\n";
		returnValue += "gcmsFilePath :" + gcmsFilePath + "\r\n";
		returnValue += "EndObject";

		return returnValue;

	}

}
